{template '_header'}

<div class="page-header">当前位置：<span class="text-primary">运营商管理</span></div>

<div class="page-content">
<form action="./index.php" method="get" class="form-horizontal" role="form" id="form1">
    <input type="hidden" name="c" value="site" />
    <input type="hidden" name="a" value="entry" />
    <input type="hidden" name="m" value="mx_shop" />
    <input type="hidden" name="do" value="web" />
    <input type="hidden" name="r" value="operator" />

    <div class="page-toolbar">
        <div class="col-sm-2">
            <div class="pull-left">
                {ifp 'operator.add'}
                <a class="btn btn-primary btn-sm" href="{php echo webUrl('operator/post')}"><i class="fa fa-plus"></i> 添加运营商</a>
                {/if}
            </div>
            <div class="input-group-btn">
                <button class="btn btn-default btn-sm"  type="button" data-toggle='refresh'><i class='fa fa-refresh'></i></button>
                {ifp 'operator.delete'}
                <button class="btn btn-default btn-sm" type="button" data-toggle='batch-remove' data-confirm="确认要删除?" data-href="{php echo webUrl('operator/delete')}"><i class='fa fa-trash'></i> 删除</button>
                {/if}
            </div>
        </div>

        <div class="col-sm-9 pull-right">
            <div class="input-group">
                <div class="input-group-select">
                    <div class="col-xs-3 col-sm-2 col-lg-2">
                        <select name="selprov" class="form-control input-sm select-md" id="selprov" onchange="loadcity();">
                            <option value="0">请选择省</option>
                            {loop $province $row}
                            <option value="{$row['province']}" {if $row['province']==$_GPC['selprov']}selected="selected"{/if}>{$row['province']}</option>
                            {/loop}
                        </select>
                    </div>
                </div>
                <div class="input-group-select">
                    <div class="col-xs-3 col-sm-2 col-lg-2">
                        <select name="selcity" class="form-control input-sm select-md" id="selcity" onchange="loaddist();">
                            <option value="0">请选择市</option>
                            {loop $city $row}
                            <option value="{$row['city']}" {if $row['city']==$_GPC['selcity']}selected="selected"{/if}>{$row['city']}</option>
                            {/loop}
                        </select>
                    </div>
                </div>
                <div class="input-group-select">
                    <div class="col-xs-3 col-sm-2 col-lg-2">
                        <select name="seldist" class="form-control input-sm select-md" id="seldist">
                            <option value="0">请选择区</option>
                            {loop $dist $row}
                            <option value="{$row['dist']}" {if $row['dist']==$_GPC['seldist']}selected="selected"{/if}>{$row['dist']}</option>
                            {/loop}
                        </select>
                    </div>
                </div>
                <div class="input-group-select">
                    <select name='type' class='form-control  input-sm select-md' style="width:100px;"  >
                    <option value="0" {if empty($type)} selected  {/if}>级别</option>
                    {loop $types $k $v}
                    <option value="{$k}" {if $k == $type} selected  {/if}>{$v}</option>
                    {/loop}
                </select>
                </div>
                <div class="input-group-select">
                <select name='status' class='form-control  input-sm select-md' style="width:100px;"  >
                    <option value="0" {if empty($status)} selected  {/if}>状态</option>
                    <option value="1" {if $status == 1} selected  {/if}>显示</option>
                    <option value="2" {if $status == 2} selected  {/if}>不显示</option>
                </select>
                </div>
                <div class="input-group-select">
                    <select name='searchfield' class='form-control  input-sm select-md' style="width:120px;margin-left: 20px;"  >
                        <option value="member" {if $_GPC['searchfield']=='member'}selected{/if}>会员信息</option>
                    </select>
                </div>
                <input type="text" class="form-control input-sm"  name="keyword" value="{$_GPC['keyword']}" placeholder="请输入关键词"/>
                <span class="input-group-btn">
                    <button class="btn btn-sm btn-primary" type="submit"> 搜索</button>
                </span>
            </div>
        </div>
    </div>
</form>
{if count($list)>0}

<table class="table table-hover table-responsive">
    <thead class="navbar-inner" >
    <tr>
        <th style="width:25px;"><input type='checkbox' /></th>
        <th style='width:40px;'>id</th>
        <th style='width:70px;'>运营商昵称</th>
        <th style='width:80px;'>运营商头像</th>
        <th style='width:60px;'>级别</th>
        <th style='width:130px;'>所属区域</th>
        <th style='width:30px;'>门店数</th>
        <th style='width:60px;'>状态</th>
        <th style='width:150px;'>操作</th>
    </tr>
    </thead>
    <tbody>
    {loop $list $row}
    <tr>
        <td>
            <input type='checkbox'   value="{$row['id']}"/>
        </td>

        <td >
            <span>{$row['id']}</span>
        </td>

        <td >
            <span><a {ifp 'user.list.view'}href="{php echo webUrl('user/list/detail',array('id'=>$row['uid']))}" target='_blank'{/if}>{$row['realname']}</a></span>
        </td>

        <td >
            <img src="{php echo tomedia($row['avatar'])}" style="width:70px;">
        </td>

        <td >
            <span>{$types[$row['type']]}</span>
        </td>

        <td >
            <span>{$row['province']}{if $row['type'] != 1}-{$row['city']}-{$row['dist']}{/if}</span>
        </td>

        <td >
            <span><a href="{php echo webUrl('mendian', array('opid'=>$row['id']))}">{php echo intval($row['mdnumber'])}</a></span>
        </td>

        <td>
            <span class='label {if $row['status']==1}label-success{else}label-default{/if}'
            {ifp 'operator.status'}
            data-toggle='ajaxSwitch'
            data-switch-value='{$row['status']}'
            data-switch-value0='0|不显示|label label-default|{php echo webUrl('operator/status',array('status'=>1,'id'=>$row['id']))}'
            data-switch-value1='1|显示|label label-success|{php echo webUrl('operator/status',array('status'=>0,'id'=>$row['id']))}'
            {/if}
            >
            {if $row['status']==1}显示{else}不显示{/if}</span>
        </td>
        <td  style="overflow:visible;">
            {ifp 'operator.edit'}
            <div class="btn-group btn-group-sm">
                {ifp 'operator.store'}
                <a class="btn btn-default dropdown-toggle" href="{php echo webUrl('mendian', array('opid'=>$row['id']))}"><i class="fa fa-edit"></i>门店</a>
                {/if}
                <a class="btn btn-default dropdown-toggle" href="{php echo webUrl('operator/post', array('id'=>$row['id']))}"><i class="fa fa-edit"></i>编辑</a>
                {ifp 'operator.delete'}
                <a data-toggle='ajaxRemove' href="{php echo webUrl('operator/delete', array('id'=>$row['id']))}" class="btn btn-default btn-sm" data-confirm="确认要删除运营商吗?"><i class="fa fa-trash"></i> 删除</a>
                {/if}
            </div>
            {/if}
        </td>
    </tr>
    {/loop}
    </tbody>
</table>
{$pager}
    {else}
    <div class="panel panel-default">
        <div class="panel-body empty-data">未查询到相关数据</div>
    </div>
    {/if}
</div>
<script language="javascript">

    function loadcity() {

        $("#selcity").html( '<option value="0">请选择市</option>');
        $("#seldist").html( '<option value="0">请选择区</option>');
        var str = $("#selprov").val();
        if(str!=0) {
            $.post("{php echo webUrl('operator/opajax',array('foo'=>'city'));}", {str: str}, function (data) {
                if (data.status == 1) {
                    var json = data.data;
                    var _html = '<option value="0">请选择市</option>';
                    for (var o in json) {
                        if (json[o].city != '') {
                            _html += '<option value="' + json[o].city + '" >' + json[o].city + '</option>';
                        }
                    }
                    $("#selcity").html(_html);
                }

            }, 'json')
        }
    }

    function loaddist(){


        $("#seldist").html( '<option value="0">请选择区</option>');
        var selcity = '#selcity';
        var str=$(selcity).val();
        if(str != 0) {

            $.post("{php echo webUrl('operator/opajax',array('foo'=>'dist'));}", {str: str}, function (data) {
                if (data.status == 1) {
                    var json = data.data;
                    var _html = '<option value="0">请选择区</option>';
                    for (var o in json) {
                        if(json[o].dist != ''){
                            _html += '<option value="' + json[o].dist + '" >' + json[o].dist + '</option>';
                        }
                    }
                    $('#seldist').html(_html);
                }

            }, 'json')
        }
    }

</script>
{template '_footer'}